/**
 * 系统管理 用户管理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true"  class="user-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="customer.customerName" placeholder="输入用户名"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-card class="box-card" style="margin-top: 10px">
    <el-table size="small" :data="userData.slice((pageNum - 1) * pageSize, pageNum * pageSize)" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="selection" width="50">
      </el-table-column>
      <el-table-column align="center" sortable prop="customerName" label="用户名" >
      </el-table-column>
      <el-table-column align="center" sortable prop="age" label="年龄" >
      </el-table-column>
      <el-table-column align="center" sortable prop="sex" label="性别" >
        <template slot-scope="scope">
          <span v-if="scope.row.sex ==0">女</span>
          <span v-if="scope.row.sex ==1">男</span>
        </template>
      </el-table-column>
      <el-table-column align="center" sortable prop="customerEmail" label="邮件" >
      </el-table-column>
      <el-table-column align="center" sortable prop="createTime" label="创建时间" >
      </el-table-column>
      <el-table-column align="center" sortable prop="modifiedTime" label="修改时间" >
      </el-table-column>
      <el-table-column label="操作" >
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="deleteUser(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
      <!--分页-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-sizes="[2, 3, 4, 5, userData.length]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="userData.length"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
// 导入请求方法
import {
  userList,
  userDelete,
} from '../../api/userMG'
import Pagination from '../../components/Pagination'
import axios from 'axios';
import {CustomerList, OrderList} from "../../api/payMG";
export default {
  data() {
    return {
      pageNum: 1,
      pageSize: 2,
      loading: false, //是显示加载
      customer:{},
      //用户数据
      userData: [],
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  created() {
    this.search()
  },

  methods: {
    //分页
    handleSizeChange(pageSize) {
      this.pageSize = pageSize;
    },
    handleCurrentChange(pageNum) {
      this.pageNum = pageNum;
    },
    // 搜索事件
    search() {
      userList(this.customer).then(res => {
        this.loading = false
        this.userData = res.data.data.list
      })
        .catch(err => {
          this.loading = false
          this.$message.error('用户加载失败，请稍后再试！')
        })
    },
    // 删除用户
    deleteUser(row) {
      this.$confirm('确定要删除吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'}).then(() => {
          // 删除
          userDelete(row.customerId)
            .then(res => {
              if (res.code == 20000) {
                this.$message({
                  message: "删除成功",
                  type: "success",
                });
              }
              this.search()
            });
        })
        .catch(() => {
          this.$message({

            type: 'info',
            message: '已取消删除！'
          })
        })
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

